/**
* Created by yyr on 2018/1/15
*已设立基金选项卡投资数据
*/
<template>
    <div>
        <div class="ca-box-border-top-none ca-p-22">
            <div class="ca-title">
                <h3>投资数据</h3>
                <div class="clear"></div>
            </div>
            <el-table
                stripe
                border
                style="width:100%"
                class="ca-table ca-m-t-10"
                :data="investingData">
                <el-table-column
                    prop="itemName"
                    label="投资项目">
                    <template slot-scope="scope">
                        <span v-if="scope.row.itemName==='合计'">合计</span>
                        <el-button v-else
                            type="text"
                            @click="goProjectDetail(scope.row.id)"
                           :disabled="!scope.row.click">{{scope.row.itemName}}</el-button>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="investmentTime"
                    label="投资时间">
                    <template slot-scope="scope">
                        {{scope.row.investmentTime==='--'?'--':$moment(scope.investmentTime).format("YYYY-MM-DD")}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="industry"
                    label="行业分类">
                    <template slot-scope="scope">
                        <span v-for="(v,i) in scope.row.industry" :key="i" class="ca-m-r-5">
                            {{v | getNameById('industry')}}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="itemState"
                    label="投资状态">
                    <template slot-scope="scope">
                        {{scope.row.itemState}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="investLoan"
                    :render-header="renderTitle"
                    label="初始投资</br>(万元)">
                    <template slot-scope="scope">
                        {{scope.row.investLoan | format1}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="investAmount"
                    :render-header="renderTitle"
                    label="目前投资</br>(万元)">
                    <template slot-scope="scope">
                        {{scope.row.investAmount | format1}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="finalHolding"
                    :render-header="renderTitle"
                    label="目前持股数</br>(万股)">
                    <template slot-scope="scope">
                        {{scope.row.finalHolding | format1}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="holdScale"
                    label="持股比例">
                    <template slot-scope="scope">
                        {{scope.row.holdScale | format1}}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="valuationAfter"
                    :render-header="renderTitle"
                    label="最新项目估值</br>(万元)">
                    <template slot-scope="scope">
                        {{scope.row.valuationAfter | format1}}
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp'
    export default {
        data() {
            return {
                itemId: this.$route.params.fundId,
                investingData: [],
            }
        },
        props: {
        },
        created() {
            this.getInvestingData();
        },
        mounted() {

        },
        methods: {
            getInvestingData() {
                apiHttp(api.GET_INVESTMENT,{fundId: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        let investLoan = 0;
                        let investAmount = 0;
                        let finalHolding = 0;
                        for (let i of ret.data) {
                            let industry = i.industry.split(',');
                            i.industry = industry;
                            investLoan = Number(investLoan) + Number(i.investLoan);
                            investAmount = Number(investAmount) + Number(i.investAmount);
                            finalHolding = Number(finalHolding) + Number(i.finalHolding);
                            if (i.itemState === '2') {
                               i.itemState = '已退出';
                            } else {
                                i.itemState = '持有中';
                            }
                        }
                        let totalData = [{
                            itemName: '合计',
                            investmentTime: '--',
                            industry: '--',
                            itemState: '--',
                            investLoan: investLoan,
                            investAmount: investAmount,
                            finalHolding: finalHolding,
                            holdScale: '--',
                            valuationAfter: '--'
                        }]
                        if (ret.data.length === 1) {
                            ret.data.map( item =>{
                                if (!item.id) {
                                    ret.data = [];
                                }
                            })
                        }
                        this.investingData = ret.data.concat(totalData);
                    }
                })
            },
            goProjectDetail(id) {
                apiHttp(api.GET_PROJECT_DETAIL,{itemId: id}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$router.push({name: 'invested-project-detail', params: {itemId: id, openWindow: true }});
                    }
                })
            }
        },
        components: {
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
